﻿
using HBase; 
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Security.Cryptography;

namespace hconnect {
    public abstract class Synchro : TestableTask {
      
       
        protected abstract AbsStatus parse(AbsStatus old);

        public override bool excute() {
            AbsStatus old=StatusCache.getStatus(this.GetType());
            AbsStatus cs = null;
            if (StatusCache.test) {
                 cs = (AbsStatus)textParse(old);
            } else {
                 cs = parse(old);
            }
              
            if( cs == null ) {
                return false;
            }
            beforeSync(cs);
            syncDb(cs);
            after(cs);

            StatusCache.setStatus(GetType() ,cs);
            BsonDocument document = BsonDocument.Parse(JsonUtil.mySerializeObject(cs)); 
            BsonDocument his = StatusCache.getHis(GetType()); 
            List<BsonDocument> defList = cs.getDef(his ,document); 
            cs.publish(defList); 
            StatusCache.addDef(defList);
            StatusCache.setHis(GetType() ,document); 
            return true;
        }

        
        protected abstract void syncDb(AbsStatus cs);
        protected virtual void after(AbsStatus cs) { 
        
        }
      
    }
}
